package ru.amse.baltijsky.javascheme.util;

import java.awt.*;

/**
 * A simple 2-dimensional size structure.
 */
public final class Size implements Cloneable {
    /**
     * Size of the projection on the x-axis.
     */
    public int x;
    /**
     * Size of the projection on the y-axis.
     */
    public int y;

    /**
     * Creates a zero size.
     */
    public Size() {
        this(0, 0);
    }

    /**
     * Creates a new size with the specified projection values. They must be non-negative.
     *
     * @param theX x-projection, non-negative
     * @param theY y-projection, non-negative
     * @throws IllegalArgumentException if one of the size components is negative
     */
    public Size(int theX, int theY) {
        if (theX < 0 || theY < 0) {
            throw new IllegalArgumentException("size must be non-negative");
        }
        x = theX;
        y = theY;
    }

    public Size clone() {
        try {
            super.clone();
        } catch (CloneNotSupportedException e) {
        }
        return new Size(x, y);
    }

    public Dimension toDimension() {
        return new Dimension(x, y);
    }
}


